package com.yuesystem.controller;

import com.yuesystem.common.R;
import com.yuesystem.entity.AcademyItem;
import com.yuesystem.entity.FixedItem;
import com.yuesystem.service.AcademyItemService;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 书院条目类.
 */
@RestController
@RequestMapping("/items")
@CrossOrigin
@Slf4j
public class AcademyItemController {
  @Autowired
  private AcademyItemService academyItemService;

  /**
   * 根据书院id获取该书院可变条目信息.
   *
   * @param id 书院id
   * @return 书院条目类
   */
  @GetMapping("/listAll/{id}")
  public R<List<AcademyItem>> getAll(@PathVariable Long id) {
    // 根据书院id获得所有该书院条目信息
    List<AcademyItem> items = academyItemService.getItems(id);

    return R.success(items);
  }

  /**
   * 根据书院id获得固定条目信息.
   *
   * @param id 书院id
   * @return 固定书院条目信息类
   */
  @GetMapping("/listFixed/{id}")
  public R<List<FixedItem>> getFixed(@PathVariable Long id) {
    List<FixedItem> items = academyItemService.getFixed(id);
    return R.success(items);
  }


  /**
   * 根据书院条目id获得条目信息.
   *
   * @param id 书院id
   * @return 书院条目类
   */
  @GetMapping("/getItem/{id}")
  public R<AcademyItem> getItemById(@PathVariable Long id) {
    AcademyItem academyItem = academyItemService.getItemById(id);
    return R.success(academyItem);
  }

}
